'''
@Author: 冯浩
@Date: 2019-12-11 23:28:11
@LastEditors: 冯浩
@LastEditTime: 2019-12-12 00:23:12
@FilePath: \bob_develop\fluent_python\示例5_23.py
'''
from operator import itemgetter
metro_data = [
    ('tokyo', 'jp', 36.933),
    ('delhi', 'in', 21.935),
    ('mexico', 'mx', 20.142),
    ('newyork', 'us', 20.104),
    ('saopaulo', 'br', 19.649)
]
# itemgetter(1) 表示按照元组中第二个元素进行排序
for city in sorted(metro_data, key=itemgetter(1)):
    print(city)

# itemgetter(1, 0)(city)表示取元组中的第二个元素和第一个元素
for city in metro_data:
    print(
        itemgetter(1, 0)(city)
    )
